<template>
  <div>
    <div class="cart-list-main flex" v-for="(item,index) in cartList" :key="item.iid">
      <div class="cart-list-left flex">
        <check-button :is-cb="item.checked" @CheckClick="item.checked=!item.checked"/>
        <img :src="item.img" alt="" class="goods-img">
      </div>
      <div class="cart-list-right">
        <div class="goods-name one-txt-cut">{{item.title}}</div>
        <div class="goods-info flex">
          <span class="price">￥{{item.price}}</span>
          <div style="position: absolute;top: -3px;left: 95px;">
            <button @click="delCartCouter(index)">-</button>
            <span> x{{item.count}} </span>
            <button @click="addCartCouter(index)">+</button>
          </div>
          <span @click="delCart(index)">删除</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CheckButton from "@/components/common/CheckButton/CheckButton";
import {Add_Counter,Delete_Counter,Delete_Cart} from "@/store/Mutations-Types";
export default {
  name: 'CartListItem',
  components:{
    CheckButton
  },
  methods:{
    delCartCouter(index){
      this.$store.commit(Delete_Counter,this.$store.state.cartList[index])
    },
    addCartCouter(index){
      this.$store.commit(Add_Counter,this.$store.state.cartList[index])
    },
    delCart(index){
      this.$store.commit(Delete_Cart,index)
    }
  },
  props: {
    cartList: {
      type: Array,
      default() {
        return []
      }
    }
  }
}
</script>

<style lang="less" scoped="scoped">
.cart-list-main {
  padding: 10px;
  border-bottom: 1px solid #ececec;
}
.cart-list-left {
  width: 26%;
  align-items: center;
  .goods-img {
    width: 52px;
    height: 66px;
    overflow: hidden;
    border: 1px solid #ececec;
    margin:0 10px;
    border-radius: 6px;
    vertical-align: middle;
  }
}
.cart-list-right {
  width: 74%;
  position: relative;
  .goods-name {
    width: 100%;
    font-size: 13px;
  }
  .goods-info {
    justify-content: space-between;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    .price {
      color: #F9CD0B;
    }
  }
}
</style>
